/**
 * Created by Administrator on 2017/7/27.
 */
angular.module('module.create_activity',[])
    .config(['$stateProvider',function ($stateProvider) {
        $stateProvider
            .state('create_activity',{
                url:'/create_activity',
                params:{originatorId:1},
                templateUrl:'view/create_activity.html',
                controller:'create_activity_controller'
            })
    }])
    .controller('create_activity_controller',['$scope','$stateParams','OriginatorService','ActivityService',
        function ($scope,$stateParams,OriginatorService,ActivityService) {
        console.log('create_activity_controller启动成功');
        $scope.activity={
            activeName:'',
            activeId:null,
            originatorId:null,
            activePlace:'',
            activeTime:null,
            activeContents:'',
            activeLimit:'',
            activeState:0,
            activeReward:'',
            auditMessage:'',
            cancelMessage:'',
            enrolmentDetails:0
        };
        console.log(38);
        //时间选框控件——————————————————————————————————————————————————————————————————————————————————————————————
        $('#activity_time')
            .datetimepicker({
                minView:1,
                autoclose:true,
                todayBtn:true,
                todayHighlight:true,
                initialDate:new Date(),
                format:'yyyy-mm-dd P HH:ii:ss'
            })
            .on('changeDate', function(date){
                console.log(date.timeStamp);
                $scope.activity.activeTime=date.timestamp;
            });
        // ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

        //修复时间选框样式——————————————————————————————————————————————————————————————————————————————————————————————————————————————
        function repair() {
            var i_left=$(".glyphicon.icon-arrow-left");
            var i_right=$(".glyphicon.icon-arrow-right");
            for (var i in i_left){
                i_left[i].className="glyphicon glyphicon-arrow-left"
            }
            for (var i in i_right){
                i_right[i].className="glyphicon glyphicon-arrow-right";
            }
            for (i=0;i<$(".datetimepicker").length-1;i++){
                $(".datetimepicker")[i].remove();
            }
        }
            repair();
        //——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

            function getOriginator(query_terms,sfun,efun) {
            OriginatorService.getOriginatorByOriginatorId(query_terms,function (data) {
                console.log(data);
                $scope.originator=data;
                if(sfun){
                    sfun()
                }
            },efun);
        }
        getOriginator({originatorId:$stateParams.originatorId},function () {
            $scope.activity.originatorId=$scope.originator.originatorId;
        });

        $scope.addActivity=function(){
            console.log('$scope.activity',$scope.activity);
            ActivityService.addActivity($scope.activity,function (data) {
                console.log('成功',data);
                $scope.activity=data;
            },function (data) {
                console.log('失败',data)
            })
        };
    }]);